//
//  ShouYeViewController.m
//  JuBoCRM
//
//  Created by iMac on 2024/1/24.
//  Copyright © 2024 iningKe. All rights reserved.
//

#import "ShouYeViewController.h"
#import "NSString+WPAttributedMarkup.h"
#import <CoreText/CoreText.h>
#import "NSDate+Helper.h"
#import "WPAttributedStyleAction.h"
#import "WPHotspotLabel.h"
#import "DaiBanShiXiangTableViewCell.h"
#import "KeHuHuiZongCollectionViewCell.h"
#import "XiaoXiTongZhiViewController.h"
#import "DaiBanShiXiangViewController.h"

#import "XinJianKeHuViewController.h" 
#import "GenJinJiLuViewController.h"
#import "BRDatePickerView.h"

#import "ZiDingYiXuanChengYuanViewController.h"

#import "ShouYeShaiXuanView.h"
#import "ShouYeJiChuShaiXuanView.h"
#import "KeHuXiangQingViewController.h"
@interface ShouYeViewController ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource>{
    UILabel *nameLabel;
    NSArray *dataSource;
    
    ShouYeShaiXuanView *gengDuoShaXuanView;
    ShouYeJiChuShaiXuanView *jiChuShaiXuanView;
    
    NSArray *jiChuChengYuanArray;
    NSArray *jiChuBuMenArray;
    
    NSArray *gengDuoChengYuanArray;
    NSArray *gengDuoBuMenArray;
    
    NSString *sceneId;
    
    
    NSArray *gengDuoShuJuArray;
    NSDictionary *gengDuoShuJuDictionary;
    
    BOOL isZhanKai;
}
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *collectionViewHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *gengDuoShaiXuanViewHeight;

@property (weak, nonatomic) IBOutlet TPKeyboardAvoidingScrollView *mainScrollView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topSpace;
@property (weak, nonatomic) IBOutlet UIView *lineView;
@property (weak, nonatomic) IBOutlet TPKeyboardAvoidingTableView *mainTableView;
@property (weak, nonatomic) IBOutlet UICollectionView *mainCollectionView;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *daiBanTopSpace;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *daiBanViewHeight;
@property (weak, nonatomic) IBOutlet UIView *daiBanView;
@property (weak, nonatomic) IBOutlet UIView *gengDuoShaoXuanShiTu;
@property (weak, nonatomic) IBOutlet UIView *allBackView;
@property (weak, nonatomic) IBOutlet UITextField *gongHaiLingQuShuLabel;
@property (weak, nonatomic) IBOutlet UITextField *xinJianShuLabel;

@property (weak, nonatomic) IBOutlet UITextField *genJinShuLabel;
@end

@implementation ShouYeViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //    消息数量显示
        [self huoQuXiaoXiWeiDuShuLiang];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
  
    
    [self.customNavBar setOnClickRightButton:^{
        XiaoXiTongZhiViewController *xiaoXi = [[XiaoXiTongZhiViewController alloc] init];
        xiaoXi.isReadClickBlock = ^{
            [self huoQuXiaoXiWeiDuShuLiang];
        };
        [self pushViewController:xiaoXi];
    }];
    

    nameLabel = [[UILabel alloc]init];
    [self.customNavBar addSubview:nameLabel];
    
    nameLabel.sd_layout
    .leftSpaceToView(self.customNavBar, 16)
    .centerYEqualToView(self.customNavBar.titleLable)
    .heightIs(30)
    .widthIs(ScreenWidth);
    
    nameLabel.textColor = rgba(24, 27, 37, 1);
    nameLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
    
    [self shouYeHuanYingYuWithName:GetHandleString(USERINFO, @"realname")];
    
   
    
    if (@available(iOS 11.0, *)) {
        self.mainScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
    self.topSpace.constant = NavaBarHeight;
    
    
    [_mainTableView registerNib:[UINib nibWithNibName:@"DaiBanShiXiangTableViewCell" bundle:nil] forCellReuseIdentifier:@"DaiBanShiXiangTableViewCell"];
    
    [_mainCollectionView registerNib:[UINib nibWithNibName:@"KeHuHuiZongCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"KeHuHuiZongCollectionViewCell"];
    
//    _collectionViewHeight.constant = 86*7;
    

    [self getInfoFromServerWithDate:[ZZPUtils getTimeFromShortTimeDa:[NSDate date]]];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeName:) name:@"changeName" object:nil];
    
    
//    更多筛选
    gengDuoShaXuanView = [ShouYeShaiXuanView view];
    [self.allBackView addSubview:gengDuoShaXuanView];
    [self addShaddowWithView:gengDuoShaXuanView];
    gengDuoShaXuanView.sd_layout
        .leftEqualToView(_allBackView)
        .rightEqualToView(_allBackView)
        .topSpaceToView(_allBackView, 123)
        .heightIs(254);
  
    gengDuoShaXuanView.hidden = YES;
    gengDuoShaXuanView.manageClickBlock = ^(NSInteger index) {
        if(index == 501){
            //            自定义成员
            [self ziDingYiShiXuanWithType:1];
        }else if(index == 502){
            //            开始时间
            [self shuJuHuiZongKaiShiShiJian:YES];
        }else if(index == 503){
            //            结束时间
            [self shuJuHuiZongKaiShiShiJian:NO];
        }else if(index == 504){
            //            确定
            gengDuoShaXuanView.hidden = YES;
            
            [self huoQuShouYeJiChuXinXi];
            
        }else if(index == 505){
            //            重置
            jiChuBuMenArray = nil;
            jiChuChengYuanArray = nil;
        }
    };
    
    
    
//    基础筛选
    jiChuShaiXuanView = [ShouYeJiChuShaiXuanView view];
    [self.allBackView addSubview:jiChuShaiXuanView];
    [self addShaddowWithView:jiChuShaiXuanView];
    jiChuShaiXuanView.sd_layout
        .leftEqualToView(_allBackView)
        .rightEqualToView(_allBackView)
        .topSpaceToView(_allBackView, 342)
        .heightIs(165);
    jiChuShaiXuanView.hidden = YES;
    
    jiChuShaiXuanView.manageClickBlock = ^(NSInteger index) {
        if(index == 501){
            //            自定义成员
            [self ziDingYiShiXuanWithType:0];
        }else if(index == 504){
            //            确定
            jiChuShaiXuanView.hidden = YES;
            [self huoQuShouYeGengDuoShuJu];
        }else if(index == 505){
            //            重置
            gengDuoBuMenArray = nil;
            gengDuoChengYuanArray = nil;
        }
        
    };

    
    [self huoQuSouYouSouSuoTiaoJian];
    
    
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self getInfoFromServerWithDate:[ZZPUtils getTimeFromShortTimeDa:[NSDate date]]];
        if([sceneId length] > 0){
            [self huoQuShouYeJiChuXinXi];
        }
        if(_gengDuoShaoXuanShiTu.hidden == NO){
            [self huoQuShouYeGengDuoShuJu];
        }
    }];

    _mainScrollView.mj_header = header;
}

//消息数量显示
- (void)huoQuXiaoXiWeiDuShuLiang{
    [[ZZPRequest getWebUtil] postNetworkRequestURLString:@"/adminMessage/queryUnreadCount" andParas:nil andShowHud:YES andTransferGottenData:^(id info, NSError *error) {
        if(!error){
            NSDictionary *data = [info objectForKey:@"data"];
            if([GetHandleString(data, @"allCount") integerValue] > 0){
                [self.customNavBar wr_setRightButtonWithImage:LocalImagePath(@"首页有消息")];
            }else{
                [self.customNavBar wr_setRightButtonWithImage:LocalImagePath(@"首页没有消息")];
            }
        }else{
            [self.customNavBar wr_setRightButtonWithImage:LocalImagePath(@"首页没有消息")];
        }
    }];
}


//查询搜索条件
- (void)huoQuSouYouSouSuoTiaoJian{
    NSMutableDictionary *paraDic = [NSMutableDictionary dictionary];
    [paraDic setValue:@"2" forKey:@"type"];
    [[ZZPRequest getWebUtil] postNetworkRequestURLString:@"/crmScene/queryScene" andParas:paraDic andShowHud:YES andTransferGottenData:^(id info, NSError *error) {
        if(!error){
            NSMutableArray *array = [NSMutableArray arrayWithArray:[info objectForKey:@"data"]];
            if(array.count > 0){
                sceneId = GetHandleString(array.firstObject, @"sceneId");
                [self huoQuShouYeJiChuXinXi];
               
            }
        }
    }];
}

//首页 公海领取 新建 今日跟进
- (void)huoQuShouYeJiChuXinXi{
    NSMutableDictionary *paraDic = [NSMutableDictionary dictionary];
    [paraDic setValue:@"1" forKey:@"page"];
    [paraDic setValue:@"15" forKey:@"limit"];
    [paraDic setValue:@"" forKey:@"search"];
    [paraDic setValue:@"2" forKey:@"type"];
    [paraDic setValue:@"" forKey:@"approvalType"];
    [paraDic setValue:sceneId forKey:@"sceneId"];
    NSMutableArray *array = [NSMutableArray array];
 
//    部门
    if(jiChuBuMenArray.count > 0){
        NSMutableArray *temp = [NSMutableArray array];
        for (NSDictionary *tempD in jiChuBuMenArray) {
            [temp addObject:GetHandleString(tempD, @"deptId")];
        }
        
        NSMutableDictionary *dataDic = [NSMutableDictionary dictionary];
        [dataDic setValue:@"structure" forKey:@"formType"];
        [dataDic setValue:@"ownerDeptId" forKey:@"name"];
        [dataDic setValue:@"3" forKey:@"type"];
        [dataDic setValue:temp forKey:@"values"];
        [array addObject:dataDic];
    }
    
    //    负责人
    if(jiChuChengYuanArray.count > 0){
        NSMutableArray *temp = [NSMutableArray array];
        for (NSDictionary *tempD in jiChuChengYuanArray) {
            [temp addObject:GetHandleString(tempD, @"userId")];
        }
        
        NSMutableDictionary *dataDic = [NSMutableDictionary dictionary];
        [dataDic setValue:@"user" forKey:@"formType"];
        [dataDic setValue:@"ownerUserId" forKey:@"name"];
        [dataDic setValue:@"3" forKey:@"type"];
        [dataDic setValue:temp forKey:@"values"];
        [array addObject:dataDic];
    }
    
    
    if(gengDuoShaXuanView.keShiTimeTf.text.length > 0 && gengDuoShaXuanView.endTimeTf.text.length > 0){
        NSMutableDictionary *dataDic = [NSMutableDictionary dictionary];
        [dataDic setValue:@"datetime" forKey:@"formType"];
        [dataDic setValue:@"createTime" forKey:@"name"];
        [dataDic setValue:@"14" forKey:@"type"];
        [dataDic setValue:@[gengDuoShaXuanView.keShiTimeTf.text,gengDuoShaXuanView.endTimeTf.text] forKey:@"values"];
        [array addObject:dataDic];
    }
    [paraDic setValue:array forKey:@"searchList"];
    [[ZZPRequest getWebUtil] postJsonNetworkRequestURLString:@"/crmCustomer/appQueryPageList" andParas:paraDic andShowHud:YES andTransferGottenData:^(id info, NSError *error) {
        if(!error){
            NSLog(@"%@",info);
            NSDictionary *dataDic = [info objectForKey:@"data"];
            _xinJianShuLabel.text = GetHandleString(dataDic, @"create");
            _gongHaiLingQuShuLabel.text = GetHandleString(dataDic, @"receive");
            _genJinShuLabel.text = GetHandleString(dataDic, @"last");
        }
    }];
}


//首页更多数据
- (void)huoQuShouYeGengDuoShuJu{
    NSMutableDictionary *paraDic = [NSMutableDictionary dictionary];
    [paraDic setValue:@"1" forKey:@"page"];
    [paraDic setValue:@"15" forKey:@"limit"];
    [paraDic setValue:@"" forKey:@"search"];
    [paraDic setValue:@"2" forKey:@"type"];
    [paraDic setValue:@"" forKey:@"approvalType"];
    [paraDic setValue:sceneId forKey:@"sceneId"];
    NSMutableArray *array = [NSMutableArray array];
 
//    部门
    if(gengDuoBuMenArray.count > 0){
        NSMutableArray *temp = [NSMutableArray array];
        for (NSDictionary *tempD in gengDuoBuMenArray) {
            [temp addObject:GetHandleString(tempD, @"deptId")];
        }
        
        NSMutableDictionary *dataDic = [NSMutableDictionary dictionary];
        [dataDic setValue:@"structure" forKey:@"formType"];
        [dataDic setValue:@"ownerDeptId" forKey:@"name"];
        [dataDic setValue:@"3" forKey:@"type"];
        [dataDic setValue:temp forKey:@"values"];
        [array addObject:dataDic];
    }
    
    //    负责人
    if(gengDuoChengYuanArray.count > 0){
        NSMutableArray *temp = [NSMutableArray array];
        for (NSDictionary *tempD in gengDuoChengYuanArray) {
            [temp addObject:GetHandleString(tempD, @"userId")];
        }
        
        NSMutableDictionary *dataDic = [NSMutableDictionary dictionary];
        [dataDic setValue:@"user" forKey:@"formType"];
        [dataDic setValue:@"ownerUserId" forKey:@"name"];
        [dataDic setValue:@"3" forKey:@"type"];
        [dataDic setValue:temp forKey:@"values"];
        [array addObject:dataDic];
    }
    
    
    [paraDic setValue:array forKey:@"searchList"];
    [[ZZPRequest getWebUtil] postJsonNetworkRequestURLString:@"/crmCustomer/appLevelQueryPageList" andParas:paraDic andShowHud:YES andTransferGottenData:^(id info, NSError *error) {
        if(!error){
            NSLog(@"%@",info);
            
            NSArray *jieGuoArray = @[@"stayPool",@"customerNum",@"newPut",@"effective",@"scheduleVisit",@"electricBusiness",@"newBusiness",@"faceEffective",@"visitCustomer",@"negotiationReview",@"deal"];
            
            gengDuoShuJuDictionary = [info objectForKey:@"data"];
            NSMutableArray *tempD = [NSMutableArray array];
            for (NSString *string in jieGuoArray) {
                if ([GetHandleString(gengDuoShuJuDictionary, string) length] > 0) {
                    [tempD addObject:string];
                }
            }
            gengDuoShuJuArray = tempD;
            [_mainCollectionView reloadData];
            
            NSInteger row = gengDuoShuJuArray.count/2;
            if (gengDuoShuJuArray.count %2 != 0) {
                row++;
            }
            
            if(row*86 < 165){
                _collectionViewHeight.constant = 165;
            }else{
                _collectionViewHeight.constant = row*86;
            }

        }
    }];
}



//选择成员部门
- (void)ziDingYiShiXuanWithType:(NSInteger)type{
    ZiDingYiXuanChengYuanViewController *shaiXuan = [[ZiDingYiXuanChengYuanViewController alloc] init];
    shaiXuan.manageResultBlock = ^(NSArray * _Nonnull yuanGongArray, NSArray * _Nonnull buMenArray) {
        if(type == 0){
    //        更多筛选
            jiChuShaiXuanView.ziDingYiTf.text = [NSString stringWithFormat:@"已选择：%ld人，%ld部门",yuanGongArray.count,buMenArray.count];
            gengDuoBuMenArray = buMenArray;
            gengDuoChengYuanArray = yuanGongArray;
        }else{
    //  基础筛选
            gengDuoShaXuanView.ziDingYiTf.text = [NSString stringWithFormat:@"已选择：%ld人，%ld部门",yuanGongArray.count,buMenArray.count];
            jiChuBuMenArray = buMenArray;
            jiChuChengYuanArray = yuanGongArray;
        }
    };
    [self pushViewController:shaiXuan];
}

//给视图添加阴影
- (void)addShaddowWithView:(UIView *)view{
    view.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.1600].CGColor;
    view.layer.shadowOffset = CGSizeMake(2.5,2.5);
    view.layer.shadowOpacity = 1;
    view.layer.shadowRadius = 5;
}

//修改用户名
- (void)changeName:(NSNotification *)noti{
    [self shouYeHuanYingYuWithName:noti.object];
}
//首页问候用户
- (void)shouYeHuanYingYuWithName:(NSString *)name{
    NSInteger hour = [[NSDate date] hour];
    NSString *helloString = @"晚上好！";
    if(hour >= 6 && hour < 11){
        helloString = @"早上好！";
    }else if(hour >= 11 && hour < 14){
        helloString = @"中午好！";
    }else if(hour >= 14 && hour < 18){
        helloString = @"下午好！";
    }
    NSDictionary* style = @{@"black": rgba(40, 120, 255, 1),@"font":[UIFont systemFontOfSize:14]};
    nameLabel.attributedText = [[NSString stringWithFormat:@"%@ <black><font>%@</font></black>",name,helloString] attributedStringWithStyleBook:style];
}


//获取当天的待办事项
- (void)getInfoFromServerWithDate:(NSString *)date{
    NSString *url = [NSString stringWithFormat:@"/crmBackLog/app/todayAppCustomer?time=%@&isHome=1",date];
    [[ZZPRequest getWebUtil] postJsonNetworkRequestURLString:url andParas:[NSMutableDictionary dictionary] andShowHud:YES andTransferGottenData:^(id info, NSError *error) {
        if(!error){
            NSDictionary *dataDic = [info objectForKey:@"data"];
        
            dataSource = [dataDic objectForKey:@"data"];
            
            if(dataSource.count == 0){
                _daiBanView.hidden = YES;
                _daiBanViewHeight.constant = 0;
                _daiBanTopSpace.constant = 0;
            }else{
                _daiBanView.hidden = NO;
                _daiBanTopSpace.constant = 12;
                if(dataSource.count>5){
                    _daiBanViewHeight.constant = 38*5+80;
                }else{
                    _daiBanViewHeight.constant = dataSource.count*38+80;
                }
            }
            
            
            [_mainTableView reloadData];
        }else{
            _daiBanView.hidden = YES;
            _daiBanViewHeight.constant = 0;
            _daiBanTopSpace.constant = 0;
        }
        
        [_mainScrollView.mj_header endRefreshing];
    }];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 38;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(dataSource.count > 5){
        return 5;
    }
    return dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DaiBanShiXiangTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DaiBanShiXiangTableViewCell"];
    NSDictionary *dataDic = dataSource[indexPath.row];
//    cell.itemImage.image = LocalImagePath(@"待办写跟进");
    
    NSDate *nextTime = [NSDate dateFromString:GetHandleString(dataDic, @"nextTime") withFormat:@"yyyy-MM-dd HH:mm:ss"];
    if([[NSDate date] daysLaterThan:nextTime] == 0){
        if([GetHandleString(dataDic, @"followup") intValue] == 1){
            cell.itemImage.image = LocalImagePath(@"待办事项已跟进");
        }else{
            cell.itemImage.image = LocalImagePath(@"待办事项写跟进");
        }
    }else{
        if([GetHandleString(dataDic, @"followup") intValue] == 1){
            cell.itemImage.image = LocalImagePath(@"待办事项已跟进");
        }else{
            cell.itemImage.image = LocalImagePath(@"待办事项已过期");
        }
    }
    
    cell.nameLabel.text = GetHandleString(dataDic, @"customerName");
    cell.phoneLabel.text = GetHandleString(dataDic, @"mobile");
    cell.userInfoClickBlock = ^{
        KeHuXiangQingViewController *xiangQing = [[KeHuXiangQingViewController alloc] init];
        xiangQing.customerId = GetHandleString(dataDic, @"customerId");
        [self pushViewController:xiangQing];
    };
    
    cell.xieJiLuClickBlock = ^{
        GenJinJiLuViewController *xinJian = [[GenJinJiLuViewController alloc] init];
        xinJian.activityTypeId = GetHandleString(dataSource[indexPath.row], @"customerId");
        xinJian.addSuccessClickBlock = ^{
            [self getInfoFromServerWithDate:[ZZPUtils getTimeFromShortTimeDa:[NSDate date]]];
        };
        [self pushViewController:xinJian];
    };
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
 
}




-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return gengDuoShuJuArray.count;
}
//创建cell
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    KeHuHuiZongCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"KeHuHuiZongCollectionViewCell" forIndexPath:indexPath];

    if(indexPath.row%2 == 0){
        cell.rightView.hidden = NO;
        cell.leftSpace.constant = 8;
        cell.rightSpace.constant = 0;
    }else{
        cell.rightView.hidden = YES;
        cell.leftSpace.constant = 0;
        cell.rightSpace.constant = 8;
    }
    NSString *key = gengDuoShuJuArray[indexPath.row];
    cell.titleLabel.text = [self genJuKeyHuoQuGengDuoShuJuJieGuo:key];
    cell.numLabel.text = GetHandleString(gengDuoShuJuDictionary, key);
    return cell;
}


- (NSString *)genJuKeyHuoQuGengDuoShuJuJieGuo:(NSString *)key{
    
    NSDictionary *dataDictionary = @{@"stayPool":@"待回收",@"customerNum":@"客户数量",@"newPut":@"(电邀)新入库",@"effective":@"(电邀)有效咨询",@"scheduleVisit":@"(电邀)预约拜访",@"electricBusiness":@"(电邀)商机",@"newBusiness":@"(面谈)新商机",@"faceEffective":@"(面谈)有效咨询",@"visitCustomer":@"(面谈)拜访客户",@"negotiationReview":@"(面谈)谈判审核",@"deal":@"(面谈)成交"};
  
    return GetHandleString(dataDictionary, key);
}




//设置item的大小
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake((ScreenWidth-64)/2, 86);
}
//设置垂直间距,默认的垂直和水平间距都是10
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}
//设置水平间距
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}

//四周的边距
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

}
//建客户
- (IBAction)jianKeHu:(UITapGestureRecognizer *)sender {
    XinJianKeHuViewController *xinJian = [[XinJianKeHuViewController alloc] init];
    [self pushViewController:xinJian];
}
//写跟进
- (IBAction)xieGenJin:(id)sender {
    GenJinJiLuViewController *xie = [[GenJinJiLuViewController alloc] init];
    xie.isFromShouYe = YES;
    [self pushViewController:xie];
}
//发起审批
- (IBAction)faShenPi:(UITapGestureRecognizer *)sender {
    
    [self.tabBarController setSelectedIndex:2];
}
//待办事项
- (IBAction)daiBan:(UIButton *)sender {
    DaiBanShiXiangViewController *danBan = [[DaiBanShiXiangViewController alloc] init];
    [self pushViewController:danBan];
}
//数据汇总点击筛选
- (IBAction)shuJuHuiZongShaiXuan:(UIButton *)sender {
    jiChuShaiXuanView.hidden = YES;
    gengDuoShaXuanView.hidden = !gengDuoShaXuanView.hidden;

}
//查看更多数据
- (IBAction)chaKanGengDuoShuJu:(UIButton *)sender {
    jiChuShaiXuanView.hidden = YES;
    gengDuoShaXuanView.hidden = YES;
    sender.selected = !sender.selected;
    if(sender.selected){
        _gengDuoShaoXuanShiTu.hidden = NO;
        _mainCollectionView.hidden = NO;
        _gengDuoShaiXuanViewHeight.constant = 48;
        [self huoQuShouYeGengDuoShuJu];
    }else{
        _gengDuoShaoXuanShiTu.hidden = YES;
        _mainCollectionView.hidden = YES;
        
        _gengDuoShaiXuanViewHeight.constant = 0;
        _collectionViewHeight.constant = 0;
    }
  
}
//更多筛选
- (IBAction)gengDuoShaiXuan:(UIButton *)sender {
    gengDuoShaXuanView.hidden = YES;
    jiChuShaiXuanView.hidden = !jiChuShaiXuanView.hidden;
}

//根据时间进行筛选
- (void)shuJuHuiZongKaiShiShiJian:(BOOL)isBegin {
    BRDatePickerView *datePickerView = [[BRDatePickerView alloc]init];
    datePickerView.pickerMode = BRDatePickerModeYMD;
    datePickerView.title = @"";
    if(isBegin && gengDuoShaXuanView.endTimeTf.text.length > 0){
        datePickerView.minDate = nil;
        datePickerView.maxDate = [NSDate dateFromString:gengDuoShaXuanView.endTimeTf.text withFormat:@"yyyy-MM-dd"];
    }
    
    if(!isBegin && gengDuoShaXuanView.keShiTimeTf.text.length > 0){
        datePickerView.maxDate = nil;
        datePickerView.minDate = [NSDate dateFromString:gengDuoShaXuanView.keShiTimeTf.text withFormat:@"yyyy-MM-dd"];
    }
    
    datePickerView.isAutoSelect = NO;

    datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
   
        NSLog(@"selectValue=%@", selectValue);
        NSLog(@"selectDate=%@", selectDate);
        NSLog(@"---------------------------------");
        if(isBegin){
            gengDuoShaXuanView.keShiTimeTf.text = selectValue;
        }else{
            gengDuoShaXuanView.endTimeTf.text = selectValue;
        }
        
    };
 
    
    BRPickerStyle *customStyle = [[BRPickerStyle alloc]init];
    customStyle.pickerColor = [UIColor whiteColor];
    customStyle.selectRowTextColor = rgba(51, 51, 51, 1);
    customStyle.titleBarColor = [UIColor whiteColor];
    customStyle.titleTextColor = [UIColor whiteColor];
    customStyle.cancelTextColor = rgba(153, 153, 153, 1);
    customStyle.doneTextColor = rgba(40, 120, 255, 1);
    customStyle.titleBarHeight = 48;
    customStyle.titleTextFont = [UIFont systemFontOfSize:18];
    datePickerView.pickerStyle = customStyle;
    customStyle.topCornerRadius = 10;
    customStyle.hiddenTitleLine = YES;
    customStyle.separatorColor = rgba(223, 229, 242, 1);
    customStyle.separatorHeight = 0.5;
    customStyle.rowHeight = 64;

    [datePickerView show];
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end





